/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UML;

import graphic.DiagramPane;
import include.fxml.DbEnter;
import include.fxml.DiagramTab;
import include.fxml.SlyumFX;
import javafx.event.EventHandler;
import javafx.geometry.Rectangle2D;
import javafx.stage.WindowEvent;

/**
 *
 * @author David
 */
public class Controller {
  
  public static Controller instance;
  
  private Controller(){}
  
  public static Controller getInstance(){
    if (instance == null)
      instance = new Controller();
    
    return instance;
  }
  
  public DiagramPane getCurrentDiagramPane() {
    DiagramTab current = SlyumFX.getInstance().getCurrentDiagramTab();
    
    if (current != null)
      return current.getDiagramPane();
    
    return null;
  }
  
  public boolean createClass(String name, Rectangle2D bounds){
    return false;
  }
  
  public void createNewClassDiagram(){
    
    final DbEnter db = new DbEnter(SlyumFX.getInstance().rb.getString("enterViewName"));
    db.setOnHidden(new EventHandler<WindowEvent>() {

      @Override
      public void handle(WindowEvent event) {
        
        if (db.isAccepted()){
          ClassDiagram cd = new ClassDiagram(db.getUserEntry());
          SlyumFX.getInstance().createNewDiagramTab(cd);
        }
      }
    });
    
    db.show();
  }
}
